import { deleteLog, LogType, saveLog } from "../utils/LogUtil"
import { DummyLogin, dummyLoginCache } from "../假人/假人登录"
import { 人物回血执行 } from "../附加功能/人物回血"
import { 挂机执行 } from "../附加功能/挂机"
// import { checkItemCustomAbi } from "../附加功能/鉴定"
import { getFreshBoss, getFreshMon, getSlaveManage } from "./GlobalObjectManage"

export function morningMsg(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {

    GameLib.Broadcast("亲爱的玩家，现在已经是早上了")
    GameLib.Broadcast("游戏虽然好玩，可别忘了工作和学习的时间")

}


export function afternoonMsg(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {


    GameLib.Broadcast("亲爱的玩家，现在已经是中午了")
    GameLib.Broadcast("游戏虽然好玩，可别忘了多陪陪你的朋友和家人")
}



export function nightMsg(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {


    GameLib.Broadcast("亲爱的玩家，现在已经是晚上了")
    GameLib.Broadcast("游戏虽然好玩，也别忘了陪朋友和家人吃顿晚饭")
}



export function dawnMsg(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {


    GameLib.Broadcast("亲爱的玩家，现在已经是凌晨了")
    GameLib.Broadcast("游戏虽然好玩，也别忘了是不是该休息了")

    let tmp: number = GameLib.GetGVar(0);
    tmp++
    GameLib.SetGVar(0, tmp);

    deleteLog()
}

//用户定时器
export function PlayRun(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {

}

//假人登录定时器
export function DummyRun(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {
    // dummyLoginCache.push({
    //     account:'a249243211',
    //     name:'测试战',
    //     x:333,
    //     y:333,
    //     map:'3',
    // })
    // DummyLogin();

    // let y:TActor;
    // y.AddedAbility.AC;
}

//假人登录定时器
export function mongen(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {
    getFreshMon().freshMon();
    getFreshBoss().freshBoss();

    let g99 = GameLib.GetGVar(99)
    if (g99 == 1) {
        for (let i = 0; i < GameLib.PlayCount; i++) {
            let play: TPlayObject = GameLib.GetPlayer(i);
            play.StopAutoFight();
            getSlaveManage().saveSlave(play, true)
            play.MessageBox("马上就要重启了,宝宝已经保存,请安全离线!")
        }
    }
}

//人物回血定时器
export function 人物回血(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {
    if (Player.Death || Player.Ghost) {
        return
    }
    人物回血执行(Player)
}
//人物回血定时器
export function 范围拾取(Npc: TNormNpc, Player: TPlayObject, OnlineAddExp: Boolean) {
    if (Player.Death || Player.Ghost) {
        return
    }
    let magic: TUserMagic = Player.FindSkill("范围拾取")
    if (magic) {
        try {
            Player.MagicAttackXYEx(Player, Player.MapX, Player.MapY, magic, false);
        }
        catch (e) {
            saveLog(`用户${Player.Name}在地图${Player.Map.MapName} ${Player.MapX},${Player.MapY} 出现异常`, LogType.SystemError)
        }
    }

    Player.R.count = (Player.R.count || 0) + 1;
    if (Player.R.count >= 20) {
        Player.R.count = 0
        for (let j = TItemWhere.wDress; j <= TItemWhere.wCharm; j++) {
            let item: TUserItem = Player.GetArmItem(j);
            if (item) {
                item.Dura = item.DuraMax
            }
        }

        // checkItemCustomAbi(Player)
        挂机执行(Player)
    }
}

